/**
 * 
 */
package com.sample.core;

import com.sample.adapter.DateTimeAdapter;
import java.io.InputStream;
import java.util.Date;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
 * Classe representant la version du projet.
 */
@XmlRootElement
@XmlType(propOrder={"name",  "dateBuild", "description"})
public class Project {

	/** Le nom du projet.*/
	private String name;
	/** Le numero de version du projet. */
	private String numeroVersion;
	/** La date de buil du projet. */
	private Date dateBuild;
	/** La description du projet. */
	private String description;

	/**
	 */
	public Project() {
	}

	/**
	 * Lecture de la configuration du projet.
	 * @return la configuration du projet
	 * @throws JAXBException
	 */
	public static Project read() throws JAXBException {
		return read(Project.class.getResourceAsStream("project.xml"));
	}

	/**
	 * @param inputStream representant le projet
	 * @return les informations sur le projet
	 * @throws JAXBException
	 */
	public static Project read(InputStream inputStream) throws JAXBException {
		final JAXBContext context = JAXBContext.newInstance(Project.class);
		return (Project) context.createUnmarshaller().unmarshal(inputStream);
	}
	
	
	@Override
	public String toString() {
		return com.google.common.base.Objects.toStringHelper(this).addValue(numeroVersion).addValue(name).addValue(dateBuild).addValue(description).toString();
	}

	@XmlAttribute
	public String getNumeroVersion() {
		return numeroVersion;
	}

	public void setNumeroVersion(String numeroVersion) {
		this.numeroVersion = numeroVersion;
	}

	@XmlJavaTypeAdapter(DateTimeAdapter.class)
	public Date getDateBuild() {
		return dateBuild;
	}

	public void setDateBuild(Date dateBuild) {
		this.dateBuild = dateBuild;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
}
